<?php
// 搜索参数
$_GET['pid'] = empty($_GET['pid']) ? 0 : intval($_GET['pid']);
$_GET['depth'] = empty($_GET['depth']) ? 0 : 1;

$oGoodscat = new Goodscat();
$list = $oGoodscat->get_category_list($_GET['pid'], '', 0, $_GET['depth']);

if(!empty($list) && is_array($list)){

	if(!empty($_GET['btnExport'])){	// 导出
		$data = array();
		foreach($list as $key => $row){
			$row['name'] = str_repeat('　　', $row['level']).$row['name'];
			$row['range'] = empty($row['range']) ? '' : str_replace(array(' ', "\n"), '', print_r($row['range'], 1));
			$row['time'] = utime($row['addtime'], $row['updatetime']);
			$data[] = $row;
		}

		$headers = array(
			'id'		=> array('title' => 'ID',		'width' => '6'),
			'name'		=> array('title' => '名称', 	'width' => '50'),
			'mark'		=> array('title' => '标识', 	'width' => '12.5'),
			'range'		=> array('title' => '价格区间', 'width' => '50', 'wrap' => true),
			'memo'		=> array('title' => '备注', 	'width' => '50', 'wrap' => true),
			'time'		=> array('title' => '时间', 	'width' => '18'),
		);
		$oExcel = new Excel();
		$oExcel->export($headers, $data, '_E_商品分类_'.date('Ymd_His').'.xlsx');
		exit;
	}

	$data = array();
	foreach($list as $key => $row){
		$row['name'] = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $row['level']).$row['name'];
		$row['attr'] = $row['attr'] == '' || $row['attr'] == 'a:0:{}' ? 0 : 1;
		$row['spec'] = $row['spec'] == '' || $row['spec'] == 'a:0:{}' ? 0 : 1;
		$row['addtime'] = ftime($row['addtime']);
		$row['updatetime'] = ftime($row['updatetime']);
		$data[] = $row;
	}
	$vars['list'] = $data;
	$vars['total'] = count($list);
}
?>